﻿#include "cookieutils.h"

CookieUtils::CookieUtils()
{

}

CookieUtils::~CookieUtils()
{

}


void CookieUtils::clearRefreshTokenCookie(HttpResponse &response)
{
    HttpCookie cookie;
    cookie.setName("jwt");
    cookie.setValue("");
    cookie.setHttpOnly(true);
    cookie.setSecure(true);
    response.setCookie(cookie);
}

void CookieUtils::setRefreshTokenCookie(HttpResponse &response, QByteArray &refreshToken)
{
    HttpCookie cookie;
    cookie.setName("jwt");
    cookie.setValue(refreshToken);
    cookie.setHttpOnly(true);
//    cookie.setMaxAge(24 * 60 * 60 * 1000);
    cookie.setMaxAge(60 * 1000);
    cookie.setSecure(true);
    response.setCookie(cookie);
}

QByteArray CookieUtils::getRefreshTokenFromCookie(HttpRequest &request)
{
    return request.getCookie("jwt");
}
